<?php
namespace app\index\controller;
use app\index\controller\Base;
class Detail extends Base
{
    
    public function index($id){ 
        if(!intval($id)){
            $this->error("id非法");
        }
        $deal=model("Deal")->get($id);
        if(!$deal  || $deal->status!=1){
            $this->error("数据不合法");
        }
        //获取分类信息
        $category=model("Category")->get($deal->category_id);
        //获取分店信息
        $locations=model("BisLocation")->getNormalLocationsInId($deal->location_ids);
        //dump($locations);exit;
        //统计库存
        $overplus=$deal->total_count-$deal->buy_count;
       //团购时间的相关
        $flag=0;
        if($deal->start_time>time()){
            $flag=1;
            $dtime=$deal->start_time-time();//离活动开始的时间
            //天
            $d=floor($dtime/(3600*24));
            $timedata="";
            if($d){
                $timedata.=$d."天";
            }
             //时
            $h=floor($dtime%(3600*24)/3600);
            if($h){
                 $timedata.=$h."时";
            }
            //分
            $m=floor($dtime%(3600*24)%3600/60);
            if($m){
                $timedata.=$m."分";
            }
            $this->assign("timedata",$timedata);
        }
         //dump($deal);exit;
        return $this->fetch("",[
            "title"=>$deal->name,
            "deal"=>$deal,
            "category"=>$category,
            "locations"=>$locations,
            "overplus"=>$overplus,
            "flag"=>$flag,
            "mapstr"=>$locations[0]['xpoint'].','.$locations[0]['ypoint'],
        ]);
    }
    
}
